/*
 * vim:foldmethod=marker:
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#define N_MAX 20000
#define M_MAX 200000

#define DFS_TREE	(1 << 4)
#define DFS_NOT_TREE	(1 << 5)
#define DFS_TSORT_OK	5141
#define	DFS_TSORT_FAIL	2342
#define COLOR_WHITE	0
#define COLOR_GRAY	1
#define COLOR_BLACK	2

struct Node {
	int x;
	int8_t is_valid;
	int edge_i;
	Node *next;
};

struct adjlist {
	Node *first;
	Node *last;
	int8_t size;

	/* Other attributes */
	int	color;
	uint8_t	visited;
	int	distance;
	int	conn_sp_id;
	uint8_t	has_bridge;
//	int	old_index_;
};


static void
pushback(struct adjlist *al, int x, int edge_i)
{
	struct Node *newnode;
	newnode = (struct Node *) calloc(1UL, sizeof (struct Node));
	newnode->x        = x;
	newnode->is_valid = 1;
	newnode->edge_i   = edge_i;
	newnode->next     = NULL;
	if (!al->first)
		al->first = newnode;
	else
		al->last->next = newnode;
	al->last = newnode;
	al->size++;
}

static void
free_al(struct adjlist *al)
{
	struct Node *n, *p;
	p = n = al->first;
	while (n) {
		n = n->next;
		free(p);
		p = n;
	}
}

void
dfs_conn_sp(struct adjlist *al, const int start, const int id)
{
	int i;
	Node *node;

	al[start].conn_sp_id = id;
	al[start].visited    = 1;
	node = al[start].first;

	while (node) {
		if (al[node->x].conn_sp_id == 0)
			dfs_conn_sp(al, node->x, id);
		node = node->next;
	}
}

int
adjlistcmp(const void *p1, const void *p2)
{
	const struct adjlist *a1=(adjlist*)p1,*a2=(adjlist*)p2;
	if (a1->conn_sp_id != a2->conn_sp_id)
		return a1->conn_sp_id - a2->conn_sp_id;
	else
		return a1 < a2 ? -1 : 1;
}

int
binsearch(const struct adjlist * const al, int size, int id)
{
	int l = 0, m, r = size - 1;
	while (l < r) {
		m = (l+r)/2;
		if (al[m].conn_sp_id == id)
			return m;
		else if (al[m].conn_sp_id < id)
			l = m + 1;
		else
			r = m;
	}
	return l;
}

int
main(void)
{
	struct adjlist	*AL;
	int		n, m, i, j, k;

	(void) scanf("%d %d", &n, &m);
	AL = (adjlist *) calloc(n, sizeof *AL);
	/*for (i = 0; i < n; ++i)
		AL[i].old_index_ = i;*/ //TODO
	for (i = 0; i < m; i++) {
		(void) scanf("%d %d", &j, &k);
		--j,--k;
		pushback(AL + j, k, i);
		pushback(AL + k, j, i);
	}

	j=k=0;
	for (i = 0; i < n; i++)
		if (AL[i].conn_sp_id == 0)
			dfs_conn_sp(AL, i, ++j);
	qsort(AL, n, sizeof *AL, adjlistcmp);

	(void) printf("%d\n", j - 1);
	//j - кол-во компонент связности
	for (i = 1; i < j; i++) {
		/*printf("%d %d\n", AL[binsearch(AL, n, i)].old_index_ + 1,
				AL[binsearch(AL, n, i+1)].old_index_ + 1);*/
		(void) printf("%d %d\n", binsearch(AL, n, i) + 1,
				binsearch(AL, n, i+1) + 1);
	}

	for (i = 0; i < n; i++)
		free_al(AL + i);
	free(AL);
	return 0;
}
